package com.uniview.filter;

import com.uniview.config.GatewayConstants;
import com.uniview.dto.RespDTO;
import com.uniview.feign.client.AuthServiceClient;
import com.uniview.utils.JacksonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author lux
 * @date: 2020/1/7
 * @desc: 访问验证前置过滤器,主要进行黑白名单过滤，权限校验
 */
@Slf4j
public class PreCheckFilter implements GlobalFilter,Ordered {
    @Autowired
    AuthServiceClient authServiceClient;
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        Map<String,Object> map = new HashMap<>();
        map.put("gatewayTest","gatewayTest");
        RespDTO<Map<String,Object>> resp = authServiceClient.test(map);
        log.info("测试返回为"+resp);
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return GatewayConstants.PRE_CHECK;
    }
}
